package cn.edu.zut.score.controller.teacher;

import cn.edu.zut.score.core.constant.RoleEnum;
import cn.edu.zut.score.core.domain.PageResponse;
import cn.edu.zut.score.core.domain.RestResponse;
import cn.edu.zut.score.core.dto.request.MessagePageRequest;
import cn.edu.zut.score.core.dto.request.PasswordRequest;
import cn.edu.zut.score.core.dto.response.MessageResponse;
import cn.edu.zut.score.core.dto.response.UserResponse;
import cn.edu.zut.score.core.entity.User;
import cn.edu.zut.score.service.IMessageService;
import cn.edu.zut.score.service.IUserService;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @author zby
 * @date 2021/06/30
 */
@RestController
@RequestMapping("/teacher")
@ApiModel("教师除答辩外api")
@CrossOrigin
public class TeacherContoller {

    @Autowired
    private IUserService iUserService;

    @Autowired
    private IMessageService iMessageService;

    @ApiOperation("分页获取当前用户消息列表")
    @PostMapping("/message/list")
    public RestResponse<PageResponse<MessageResponse>> getMessages(@RequestBody MessagePageRequest messagePageRequest) {
        return iMessageService.getMessages(messagePageRequest);
    }

    @ApiOperation("按Id设置消息为已读")
    @PutMapping("/message/read/{messageid}")
    public RestResponse<String> setRead(@PathVariable("messageid") Long messageId) {
        return iMessageService.setRead(messageId);
    }

    @ApiOperation("获取当前教师信息")
    @GetMapping("/info")
    public RestResponse<UserResponse> getCurrentTeacher() {
        return iUserService.getCurrentUser();
    }

    @ApiOperation("修改当前教师信息")
    @PutMapping("/info")
    public RestResponse<UserResponse> updateCurrentTeacher(@RequestBody User teacher) {
        return iUserService.updateCurrentUser(teacher, RoleEnum.teacher);
    }

    @ApiOperation("修改当前教师密码")
    @PutMapping("/p")
    public RestResponse<UserResponse> restCurrentTeacherPassword(@RequestBody PasswordRequest passwordRequest) {
        return iUserService.restCurrentUserPassword(passwordRequest);
    }
}
